package com.gtw.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.ApiResult;
import com.foxinmy.weixin4j.model.Button;
import com.foxinmy.weixin4j.mp.WeixinProxy;
import com.foxinmy.weixin4j.type.ButtonType;

import java.util.ArrayList;
import java.util.List;

/**
 * 微信公众号的菜单管理
 */
public class MenuManager {
    private WeixinProxy weixinProxy;
    public MenuManager (){
        weixinProxy=new WeixinProxy();
    }
    public List<Button> initMenu(){
        List<Button> buttons=new ArrayList<>();
        buttons.add(buttonMain1());
        buttons.add(buttonMain2());
        buttons.add(buttonMain3());
        return buttons;
    }

    /***
     * 商城
     * @return
     */
    private Button buttonMain1(){
        Button button=new Button("进入商城","http://jss.youwenyuedu.com", ButtonType.view);
        return button;
    }
    private Button buttonMain2(){
        Button button=new Button("会员中心",subButton2_1(),subButton2_2());
        return button;
    }
    private Button  buttonMain3(){
        Button button=new Button("酒先生","jxs",ButtonType.click);
        return button;
    }

   /*private Button subButton3_5() {
        Button button=new Button("校园招募","XYZM", ButtonType.click);
        return button;
    }*/

    private Button subButton2_1() {
        Button button=new Button("个人中心","http://jss.youwenyuedu.com/#/mine", ButtonType.view);
        return button;
    }

    private Button subButton2_2() {
        Button button=new Button("我的二维码","http://jss.youwenyuedu.com/#/MyQRCode", ButtonType.view);
        return button;
    }

    private Button subButton3_4() {
        Button button=new Button("物流详情","https://v.xiumi.us/board/v5/2Zq4K/102064854", ButtonType.view);
        return button;
    }

    private Button subButton3_3() {
        Button button=new Button("往期内容","https://mp.weixin.qq.com/mp/homepage?__biz=MzU3NTU5Mzg1Nw%3D%3D&hid=1&sn=4855fa78ad086f9f1700fc0d3b3fec38", ButtonType.view);
        return button;
    }

    private Button subButton3_2() {
        Button button=new Button("商务合作","https://jinshuju.net/f/eZiCQe", ButtonType.view);
        return button;
    }

    private Button subButton3_1() {
        Button button=new Button("自我介绍","https://v.xiumi.us/board/v5/2Zq4K/102051628", ButtonType.view);
        return button;
    }

    public static void main(String[] args) throws WeixinException, JsonProcessingException {
        MenuManager menuManager=new MenuManager();
        ObjectMapper objectMapper=new ObjectMapper();
        List<Button> buttons = menuManager.initMenu();
        ApiResult menu = menuManager.weixinProxy.createMenu(buttons);
        System.out.println(objectMapper.writeValueAsString(menu));
    }

}
